using System.Xml.Linq;
using TestCases.Assertions;

namespace TestCases.XmlAssert
{
    internal class AssertBase
    {
        protected readonly IAssertion AssertionMethod;

        public AssertBase(IAssertion assertion)
        {
            AssertionMethod = assertion;
        }

        public string Namespace { get; set; }
        public QualifyForm QualifyForm { get; set; }

        public XName GetName(QualifyForm form, string name)
        {
            return (form == QualifyForm.Qualified && Namespace != null)
                ? XName.Get(name, Namespace)
                : XName.Get(name);
        }

        public void Assert(bool expression, string message)
        {
            AssertionMethod.Assert(expression, "XAssert: " + message);
        }

        public void Assert(bool expression, string format, params object[] args)
        {
            Assert(expression, string.Format(format, args));
        }
    }
}